package com.example.tests;

import java.io.File;
import java.util.Iterator;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;
import com.example.utils.SortedListOf;
import static com.example.fw.ContactHelper.CREATION;
import static com.example.tests.ContactDataGenerator.loadContactsFromXmlFile;

public class ContactCreationTests extends TestBase {
	
	@DataProvider
	public Iterator<Object[]> contactsFromFile() throws Exception{
		return wrapContactsForDataProvider(loadContactsFromXmlFile(new File("contact.xml"))).iterator();
	}
	 
  @Test(dataProvider = "contactsFromFile")
  public void testContactCreationWithValidData(ContactData contact) throws Exception {
 	// save old state
	SortedListOf<ContactData> oldList = app.getContactHelper().getDbContacts();
    
    //action
    app.getContactHelper().createContact(contact,CREATION);
    
    //save new state
    SortedListOf<ContactData> newList = app.getContactHelper().getUiFullContacts();
    
    //compare states  
    assertThat(newList, equalTo(oldList.withAdded(contact)));
    
  }
}
